package com.fhz.kotlinmvvm.utils

import io.reactivex.Observer
import okhttp3.OkHttpClient
import okhttp3.logging.HttpLoggingInterceptor
import retrofit2.Retrofit
import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory
import retrofit2.converter.gson.GsonConverterFactory

/**
 * 时间:2023/9/12
 * @author Mr.Feng
 * 简述:
 */
object RetrofitManager {

    private var retrofit:Retrofit? = null

    fun getRetrofit() : Retrofit {
        if(retrofit == null){
           retrofit =  Retrofit.Builder().run {
                baseUrl("http://10.161.9.80:9999/")
                client(getClient())
                addConverterFactory(GsonConverterFactory.create())
                build()
            }
        }
        return retrofit!!
    }

    private fun getClient():OkHttpClient{
        return  OkHttpClient()
                .newBuilder().addInterceptor(HttpLoggingInterceptor()
                .setLevel(HttpLoggingInterceptor.Level.BODY)).build()
    }
}